package cn.com.homeyoda.aimate.aihealth.ui.videoinspect;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;

import com.google.gson.JsonObject;
import com.wzq.mvvmsmart.event.SingleLiveEvent;
import com.wzq.mvvmsmart.event.StateLiveData;
import com.wzq.mvvmsmart.http.ResponseThrowable;
import com.wzq.mvvmsmart.utils.KLog;
import com.wzq.mvvmsmart.utils.RxUtils;
import com.wzq.mvvmsmart.utils.ToastUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import cn.com.homeyoda.aimate.aihealth.base.BaseViewModel;
import cn.com.homeyoda.aimate.aihealth.bean.BaseResponse2;
import cn.com.homeyoda.aimate.aihealth.bean.BindUserQrCode;
import cn.com.homeyoda.aimate.aihealth.bean.DeviceIdBean;
import cn.com.homeyoda.aimate.aihealth.bean.DeviceIsAuthBean;
import cn.com.homeyoda.aimate.aihealth.bean.ExaminationReportDetailsBean;
import cn.com.homeyoda.aimate.aihealth.bean.FaceInfoBean;
import cn.com.homeyoda.aimate.aihealth.bean.HomeReportListBean;
import cn.com.homeyoda.aimate.aihealth.bean.IsShowCompleteInfoBean;
import cn.com.homeyoda.aimate.aihealth.bean.ReplenishChronicBean;
import cn.com.homeyoda.aimate.aihealth.bean.UploadFileBean;
import cn.com.homeyoda.aimate.aihealth.bean.UploadVideoBean;
import cn.com.homeyoda.aimate.aihealth.data.AddFaceBean;
import cn.com.homeyoda.aimate.aihealth.data.FaceIdBean;
import cn.com.homeyoda.aimate.aihealth.data.Repository;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * Created By liuxinhua
 * Created Time 2025/2/27
 */
public class VideoInspectModel extends BaseViewModel<Repository> {

    public StateLiveData<String> stateVideoUrlData;
    public StateLiveData<UploadVideoBean> stateLiveData;
    public StateLiveData<List<HomeReportListBean.RowsBean>> stateRecordData;
    public StateLiveData<IsShowCompleteInfoBean> stateIsShowData;

    public StateLiveData<ExaminationReportDetailsBean> stateReportData;//体检报告详情
    private String[] strings = {"低血压","高血压","高血脂","冠心病","糖尿病","低血糖"};

    public StateLiveData<List<ReplenishChronicBean.DataBean>> stateChronicData;
    public StateLiveData<List<String>> stateBingData;
    String url = "";
    public StateLiveData<DeviceIsAuthBean> deviceIsAuthData;
    public StateLiveData<BaseResponse2> updateInfoData;
    public StateLiveData<BaseResponse2> deleteReportData;
    public StateLiveData<UploadFileBean> uploadFileData;
    public StateLiveData<FaceInfoBean> faceInfoData;

    public StateLiveData<DeviceIdBean> deviceIdData;
    public StateLiveData<BindUserQrCode> bindUserData;
    public int pageNum = 1;
    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        //下拉刷新完成
        public SingleLiveEvent<Object> finishRefreshing = new SingleLiveEvent<Object>();
        //上拉加载完成
        public SingleLiveEvent<Object> finishLoadMore = new SingleLiveEvent<Object>();
    }


    public VideoInspectModel(@NonNull Application application, Repository model) {
        super(application, model);
        stateVideoUrlData = new StateLiveData<>();
        stateLiveData = new StateLiveData<>();
        stateBingData = new StateLiveData<>();
        stateBingData.setValue(new ArrayList<String>());
        stateRecordData = new StateLiveData<>();
        stateRecordData.setValue(new ArrayList<>());
        deviceIsAuthData = new StateLiveData<>();
        stateIsShowData = new StateLiveData<>();
        stateReportData = new StateLiveData<>();
        stateChronicData = new StateLiveData<>();
        updateInfoData = new StateLiveData<>();
        deleteReportData = new StateLiveData<>();
        uploadFileData = new StateLiveData<>();
        faceInfoData = new StateLiveData<>();
        deviceIdData = new StateLiveData<>();
        bindUserData = new StateLiveData<>();

        // TODO: 2025/4/14 测试用，登录接口调通后要删除
        Log.i("xxxxx", "model.getUserId()==="+model.getUserId());
        model.saveFamilyId("1364262316346306560");
        model.saveFaceId("1");
        model.savePhone("18161861855");
        model.saveUserId("1339958491544162304");
        model.saveDeviceId("1343626709614071809");
//        if (TextUtils.isEmpty(model.getUserId())) {
//            model.saveFamilyId("1364262316346306560");
//            model.saveFaceId("1");
//            model.savePhone("18161861855");
//            model.saveUserId("1339958491544162304");
//            model.saveDeviceId("1343626709614071809");
//        }

    }

    public void requestData() {
        model.getVideoUrl()
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<BaseResponse2<Object>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        stateVideoUrlData.postLoading();
                    }

                    @Override
                    public void onNext(BaseResponse2<Object> objectBaseResponse2) {
                        if(objectBaseResponse2.getCode() == 200){
                            stateVideoUrlData.postSuccess();
                            url = (String) objectBaseResponse2.getData();
                            stateVideoUrlData.setValue(url);
                            stateVideoUrlData.postValueAndSuccess(stateVideoUrlData.getValue());
                        }

                    }



                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        stateVideoUrlData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        stateVideoUrlData.postIdle();

                    }
                });
    }

    public void uploadVideo(MultipartBody.Part videoPart, RequestBody deviceIdBody){
        model.uploadVideo(videoPart,deviceIdBody)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<BaseResponse2<UploadVideoBean>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
//                        stateLiveData.postLoading();
                    }

                    @Override
                    public void onNext(BaseResponse2<UploadVideoBean> uploadVideoBeanBaseResponse2) {
                        Log.i("huahua","uploadVideoBeanBaseResponse2====="+uploadVideoBeanBaseResponse2.toString());
                        if(uploadVideoBeanBaseResponse2.getCode() == 200){
                            //UploadVideoBean data = uploadVideoBeanBaseResponse2.getData();
                            //stateLiveData.postSuccess();
                            //stateLiveData.getValue().add(data);
                            stateLiveData.postValueAndSuccess(uploadVideoBeanBaseResponse2.getData());
                        }
                    }


                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        Log.i("huahua","stateLiveData.getMessage()====="+e.getMessage());
                        Log.i("huahua","e.getMessage()====="+e.getMessage().toString());
                        //关闭对话框
//                        stateLiveData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
//                        stateLiveData.postIdle();

                    }
                });
    }


    public void isShowCompleteInfo(String faceId){
        model.isShowCompleteInfo(faceId)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<IsShowCompleteInfoBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //stateIsShowData.postLoading();
                    }

                    @Override
                    public void onNext(IsShowCompleteInfoBean isShowCompleteInfoBean) {
                        if(isShowCompleteInfoBean.getCode() == 200){
                            //UploadVideoBean data = uploadVideoBeanBaseResponse2.getData();
                            //stateLiveData.postSuccess();
                            //stateLiveData.getValue().add(data);
                            stateIsShowData.postValueAndSuccess(isShowCompleteInfoBean);
                        }
                    }


                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        Log.i("huahua","stateLiveData.getMessage()====="+e.getMessage());
                        Log.i("huahua","e.getMessage()====="+e.getMessage().toString());
                        //关闭对话框
                        //stateIsShowData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //stateIsShowData.postIdle();

                    }
                });
    }

    public void examinationReportDeta(String reportId){
        model.examinationReportDetails(reportId)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<ExaminationReportDetailsBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        stateReportData.postLoading();
                    }

                    @Override
                    public void onNext(ExaminationReportDetailsBean examinationReportDetailsBean) {
                        if(examinationReportDetailsBean.getCode() == 200){
                            //UploadVideoBean data = uploadVideoBeanBaseResponse2.getData();
                            //stateLiveData.postSuccess();
                            //stateLiveData.getValue().add(data);
                            stateReportData.postValueAndSuccess(examinationReportDetailsBean);
                        }
                    }


                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        Log.i("huahua","stateLiveData.getMessage()====="+e.getMessage());
                        Log.i("huahua","e.getMessage()====="+e.getMessage().toString());
                        //关闭对话框
                        stateReportData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        stateReportData.postIdle();

                    }
                });
    }




    public void chronicList(String faceId){
//        List<String> stringList = new ArrayList<>();
//        for(String str : strings){
//            stringList.add(str);
//        }
//
//
//        stateBingData.postSuccess();
//        stateBingData.getValue().addAll(stringList);
//        stateLiveData.postValueAndSuccess(stateLiveData.getValue());

        model.replenishChronicList(faceId)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<ReplenishChronicBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        stateChronicData.postLoading();
                    }

                    @Override
                    public void onNext(ReplenishChronicBean replenishChronicBean) {
                        if(replenishChronicBean.getCode() == 200){
                            //UploadVideoBean data = uploadVideoBeanBaseResponse2.getData();
                            //stateLiveData.postSuccess();
                            //stateLiveData.getValue().add(data);
                            stateChronicData.postValueAndSuccess(replenishChronicBean.getData());
                        }
                    }


                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        Log.i("huahua","stateLiveData.getMessage()====="+e.getMessage());
                        Log.i("huahua","e.getMessage()====="+e.getMessage().toString());
                        //关闭对话框
                        stateChronicData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        stateChronicData.postIdle();

                    }
                });

    }


    public void updateInfo(JsonObject params){

        model.completeInfo(params)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<BaseResponse2>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(BaseResponse2 baseResponse2) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        if(baseResponse2.getCode() == 200){
                            updateInfoData.postValueAndSuccess(baseResponse2);
                        }


                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public void recordData(String deviceSn){


        model.homeReportList(deviceSn, model.getFamilyId(), String.valueOf(pageNum),"10")
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<HomeReportListBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(HomeReportListBean homeReportListBean) {
                        if(homeReportListBean.getCode() == 200){
                            List<HomeReportListBean.RowsBean> datas = homeReportListBean.getRows();
                            if (datas != null){
                                if (datas.size() > 0){
                                    if (pageNum == 1){
                                        stateRecordData.getValue().clear();
                                    }

                                    stateRecordData.getValue().addAll(datas);
                                    Log.i("huahua","stateRecordData===="+stateRecordData.getValue().size());
                                    stateRecordData.postValueAndSuccess(stateRecordData.getValue());
                                }else {
                                    ToastUtils.showShort("没有更多数据了");
                                    KLog.e("请求到数据students.size" + datas.size());
                                }
                            }else {
                                KLog.e("数据返回null");
                                stateRecordData.postError();
                            }
//                            stateRecordData.postValueAndSuccess(homeReportListBean);
                        }

                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
//                        if(homeReportListBean.getCode() == 200){

//                        }


                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        //关闭对话框
                        stateRecordData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();
                        //请求刷新完成收回
                        stateRecordData.postIdle();
                        uc.finishRefreshing.call();
                        uc.finishLoadMore.call();
                    }
                });
    }


    public void deviceIsAuth(String deviceSn){

        model.deviceIsAuth(deviceSn)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<DeviceIsAuthBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(DeviceIsAuthBean deviceIsAuthBean) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        deviceIsAuthData.postValueAndSuccess(deviceIsAuthBean);

                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public void deleteReport(String id){

        model.deleteReport(id)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<BaseResponse2>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(BaseResponse2 baseResponse2) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        deleteReportData.postValueAndSuccess(baseResponse2);

                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public void uploadFile(RequestBody Body){

        model.uploadFile(Body)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<UploadFileBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(UploadFileBean uploadFileBean) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        uploadFileData.postValueAndSuccess(uploadFileBean);

                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public void faceInfo(String faceId){

        model.queryFaceInfo(faceId,model.getFamilyId())
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<FaceInfoBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(FaceInfoBean faceInfoBean) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        faceInfoData.postValueAndSuccess(faceInfoBean);

                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public void getDeviceId(String devieSn){
        model.getDeviceId(devieSn)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<DeviceIdBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(DeviceIdBean deviceIdBean) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        if(deviceIdBean.getCode() == 200){
                            deviceIdData.postValueAndSuccess(deviceIdBean);
                        }


                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public void getBindUser(String devieSn){
        model.getBindUserQrCode(devieSn)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<BindUserQrCode>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        //deviceIsAuthData.postLoading();
                    }

                    @Override
                    public void onNext(BindUserQrCode bindUserQrCode) {
                        //deviceIsAuthData.postSuccess();
                        //deviceIsAuthData.setValue(baseResponse2);
                        if(bindUserQrCode.getCode() == 200){
                            bindUserData.postValueAndSuccess(bindUserQrCode);
                        }


                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        //关闭对话框
                        //deviceIsAuthData.postError();
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                        //请求刷新完成收回
                        //deviceIsAuthData.postIdle();

                    }
                });
    }

    public String getFaceId() {
        return model.getFaceId();
    }

    public void queryFaceIdByImage(String imagePath) {

        File imageFile = new File(imagePath);
        RequestBody videoRequestBody = RequestBody.create(
                MediaType.parse("image/*"),
                imageFile);
        MultipartBody.Part imagePart = MultipartBody.Part.createFormData(
                "file",
                imageFile.getName(),
                videoRequestBody
        );

        model.queryFaceIdByImage(imagePart)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<FaceIdBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onNext(FaceIdBean faceIdBean) {
                        if (faceIdBean.getCode() == 200) {
                            // bindUserData.postValueAndSuccess(faceIdBean);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        // 关闭对话框
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                    }
                });
    }

    public void uploadFaceImage(String imagePath) {

        File imageFile = new File(imagePath);
        RequestBody videoRequestBody = RequestBody.create(
                MediaType.parse("image/*"),
                imageFile);
        MultipartBody.Part imagePart = MultipartBody.Part.createFormData(
                "file",
                imageFile.getName(),
                videoRequestBody
        );

        model.uploadFaceImage(imagePart)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<AddFaceBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onNext(AddFaceBean addFaceBean) {
                        if (addFaceBean.getCode() == 200) {
                            // bindUserData.postValueAndSuccess(addFaceBean);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        // 关闭对话框
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                    }
                });
    }

    public void uploadExaminationVideo(String imagePath) {

        File imageFile = new File(imagePath);
        RequestBody videoRequestBody = RequestBody.create(
                MediaType.parse("video/*"),
                imageFile);
        MultipartBody.Part videoPart = MultipartBody.Part.createFormData(
                "file",
                imageFile.getName(),
                videoRequestBody
        );

        RequestBody useDeviceIdBody = RequestBody.create(
                MediaType.parse("text/plain"),
                "useDeviceId");
        RequestBody faceIdBody = RequestBody.create(
                MediaType.parse("text/plain"),
                "faceId");
        RequestBody deviceIdBody = RequestBody.create(
                MediaType.parse("text/plain"),
                "deviceId");

        model.uploadExaminationVideo(videoPart, useDeviceIdBody, faceIdBody, deviceIdBody)
                .compose(RxUtils.observableToMain())
                .compose(RxUtils.exceptionTransformer())
                .doOnSubscribe(VideoInspectModel.this)
                .subscribe(new Observer<BaseResponse2>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onNext(BaseResponse2 baseResponse) {
                        if (baseResponse.getCode() == 200) {
                            // bindUserData.postValueAndSuccess(baseResponse);
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        KLog.e("进入onError" + e.getMessage());
                        // 关闭对话框
                        if (e instanceof ResponseThrowable) {
                            ToastUtils.showShort(((ResponseThrowable) e).message);
                        }
                    }

                    @Override
                    public void onComplete() {
                        KLog.e("进入onComplete");
                    }
                });
    }

}
